/*
 * @Author: _LJP 2634716776@qq.com
 * @Date: 2024-01-07 15:50:34
 * @LastEditors: _LJP 2634716776@qq.com
 * @LastEditTime: 2024-01-22 22:38:45
 * @FilePath: /my_-linux/Pro24/Tree/Map_Set/Set.hpp
 * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
 */
#pragma once

#include "RBTree.hpp"

enum COLOR;

namespace MYSTL
{
    template<class K>
    class Set
    {
        struct setKeyOfT
        {
            const K &operator()(const K &key)
            {
                return key;
            }
        };
        

    public:
        typedef typename RBTree<K, K, setKeyOfT>::iterator iterator;
        //typedef类模板的时候需要加上typename ,否则编译器不知道typedef的是类型还是成员变量

        std::pair<iterator,bool> Insert(const K& key){
            pair<iterator,bool> ret =  _rbt.Insert(key);
            return ret;
        }

        iterator begin(){
            return _rbt.begin();
        }

        iterator end(){
            return _rbt.end();
        }
    protected:
    

    private:
    
        RBTree<K , K , setKeyOfT> _rbt; 
        // 模板参数传入两个参数都为K
    };
    void Settest1()
    {
        Set<int> s1;
        
        
        s1.Insert(1);
        s1.Insert(3);
        s1.Insert(2);

        Set<int>::iterator it = s1.begin();
        while(it!=s1.end()){
            cout<<*it<<endl;
            it++;
        }

        cout<<"--------------------->"<<endl;

        it = s1.end();
        // --it;  
        // cout<<*it<<endl;

        
    }

    void Settest2(){
        int a[] = {16,3,7,11,9,26,18,14,15};
        Set<int> s;
        for(auto e:a){
            s.Insert(e);
        }

        Set<int>::iterator it = s.begin();
        while(it!=s.end()){
            cout<<*it<<" ";
            ++it;
        }
        cout<<endl;

        for(auto &e:s){
            cout<<e<<" ";
        }
        cout<<endl;
    }
}